package com.longrise.co.ui.carfiles.model;

import com.google.gson.reflect.TypeToken;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.co.api.ApiConstants;
import com.longrise.co.api.ApiService;
import com.longrise.co.ui.carfiles.contract.CarFilesContract;
import com.ly.common.basebean.BaseResponse;
import com.ly.common.baserx.RxResponseFuncForCar;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by luoyang on 2017-6-23.
 */

public class CarFilesModel implements CarFilesContract.Model {

    @Override
    public Observable<RepairRecord> repairRecordRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<RepairRecord>>(){}.getType(), bean, ApiConstants.APPSEARCHREPAIRLIST)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<RepairRecord>());
    }

    @Override
    public Observable<UploadBean> uploadPhotoRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<UploadBean>>(){}.getType(), bean, ApiConstants.UPLOADIMAGES)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<UploadBean>());
    }

    @Override
    public Observable<ComplaintBean> carComplaintRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<ComplaintBean>>(){}.getType(), bean, ApiConstants.APPCOMPLAIN)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<ComplaintBean>());
    }

    @Override
    public Observable<EvaluationBean> carEvaluationRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<EvaluationBean>>(){}.getType(), bean, ApiConstants.APPEVALUATE)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<EvaluationBean>());
    }

    @Override
    public Observable<RepairRecordDetail> repairRecordDetailRequest(EntityBean bean) {
        return ApiService.getInstance().request(new TypeToken<BaseResponse<RepairRecordDetail>>(){}.getType(), bean, ApiConstants.APPSEARCHREPAIRDETAIL)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .map(new RxResponseFuncForCar<RepairRecordDetail>());
    }
}
